package com.zzyl.controller;

import com.aliyun.iot20180120.models.*;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.entity.Device;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description DeviceController
 * @Author CWJ
 * @Date 2025-05-19  18:23
 */


@RestController
@RequestMapping("/iot")
@Api(tags = "管理端 - 物联网iot相关接口")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    /**
     * 从物联网平台同步产品列表到redis中
     *
     * @return
     */
    @PostMapping("/syncProductList")
    @ApiOperation("从物联网平台同步产品列表")
    public ResponseResult syncProductList() {
        deviceService.syncProductList();
        return ResponseResult.success();
    }

    /**
     * 查询所有产品列表
     */
    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProuct() {
        return ResponseResult.success(deviceService.allProuct());
    }

    /**
     * 注册设备
     * @param deviceDto
     * @return
     */

    @PostMapping("/RegisterDevice")
    @ApiOperation(value = "注册设备")
    public ResponseResult registerDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.registerDevice(deviceDto);
        return ResponseResult.success();
    }

    /**
     * 分页查询设备
     * @param devicePageQueryDto
     * @return
     */

    @GetMapping("/pageQueryDevice")
    @ApiOperation(value = "分页查询设备")
    public ResponseResult<PageResponse<DeviceVo>>PageQueryDevice(DevicePageQueryDto devicePageQueryDto) {
        PageResponse<DeviceVo> pageResponse = deviceService.pageQueryDevice(devicePageQueryDto);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 查询设备详情数据
     * @param
     * @return
     */
    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> QueryDeviceDetail(@RequestBody QueryDeviceDetailRequest QueryData) {
        return ResponseResult.success(deviceService.QueryDeviceDetail(QueryData));
    }


    /**
     * 查看指定产品的已发布物模型中的功能定义详情
     * @param
     * @return
     */
    // @PostMapping("/QueryThingModelPublished")
    // @ApiOperation(value = "查看指定产品的已发布物模型中的功能定义详情")
    // public ResponseResult<QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData> QueryThing(@RequestBody QueryThingModelPublishedRequest request){
    //     return ResponseResult.success(deviceService.QueryThingModelPublished(request));
    // }
    @PostMapping("/QueryThingModelPublished")
    @ApiOperation(value = "查看指定产品的已发布物模型中的功能定义详情")
    public ResponseResult<QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData> queryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request) {
        return deviceService.queryThingModelPublished(request);
    }

    /**
     * 查询指定设备的物模型运行状态
     * @param request
     * @return
     */
    // @PostMapping("/QueryDevicePropertyStatus")
    // @ApiOperation(value = "查询指定设备的物模型运行状态")
    // public ResponseResult<QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData> queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
    //     return deviceService.queryDevicePropertyStatus(request);
    // }
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询指定设备的物模型运行状态")
    public ResponseResult<QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData> queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        return deviceService.queryDevicePropertyStatus(request);
    }

    /**
     * 修改设备信息
     * @param deviceDto
     * @return
     */
    @PostMapping("/UpdateDevice")
    @ApiOperation(value = "修改设备信息")
    public ResponseResult updateDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.updateDevice(deviceDto);
        return ResponseResult.success();
    }

    /**
     * 删除设备
     * @param request
     * @return
     */
    @DeleteMapping("/DeleteDevice")
    @ApiOperation(value = "删除设备")
    public ResponseResult deleteDevice(@RequestBody DeleteDeviceRequest request) {
        deviceService.deleteDevice(request);
        return ResponseResult.success();
    }


}
